package com.learn.question;

/**
 * @author wangxing
 * @version 2020/7/30 10:39 Administrator
 */
public class Temp20200730 {
    /*
     * 1 10进制转2进制
     * 2 递归计算数字阶乘
     * 3 计算一个数据从高处落地每次掉落剩余原有高度的一半,100m掉落时第十次的反弹是多高,第十次时总共运行了多少距离
     * */
    public static String toBinaryString1(Integer num) {
        return Integer.toBinaryString(num);
    }

    public static String toBinaryString2(Integer num) {
        String binary = "";
        if (num == 0) {
            binary = "0";
        }
        while (num != 0) {
            binary = num % 2 + binary;
            num /= 2;
        }
        return binary.toString();
    }

    public static Long getNumMultiplicationOrder(Long num) {
        if (num == 1) {
            return num;
        }
        return num * getNumMultiplicationOrder(num - 1);
    }

    /**
     * 获取指定次数掉落后的距离
     *
     * @param num
     * @param Height
     * @return
     */
    public static Double countAppointNumDistance(Integer num, Double Height) {
        Double distance = Height;
        for (int i = 0; i < num; i++) {
            Height /= 2;
            distance += Height;
        }
        return distance;
    }

    /**
     * 获取指定次数掉落后的距离
     *
     * @param num
     * @param Height
     * @return
     */
    public static Double countAppointNumHeight(Integer num, Double Height) {
        Double distance = 0D;
        for (int i = 0; i < num; i++) {
            Height /= 2;
        }
        distance = Height;
        return distance;
    }

}
